var ClubFloorsWanfaFilterWindow = Window.extend({
    _ccsFileName: res.ClubFloorsWanfaFilterWindow_json,
    _clubId: null,
    _btnList: [],
    _selectWanfa: null,
    initWindow: function (clubId) {
        this._clubId = clubId;
        this._nodeList['btn0'].setVisible(false);
        this.refreshScrollView();

    },
    _initClickListeners: function () {
        this._clickListeners = {
            'btn_ok': '_clickOk',
            'panel': '_clickPanel',
        };
    },

    refreshScrollView: function () {
        this._btnList = [];
        var wanfaList = this.getAppFloorAndWanfaInfo();
        var scrollView = this._nodeList['scrollView'];
        scrollView.removeAllChildren();

        var len = Math.ceil(wanfaList.length / 4);
        var tmpHeight = len * 65;
        var innerHeight = Math.max(scrollView.getContentSize().height, tmpHeight);

        var listIndex = 0;
        var index = 1;
        for (var i = 0; i < wanfaList.length; i += 4) {
            var node = new cc.Node();
            for (var j = 0; j < 4; j++) {
                if (wanfaList[listIndex]) {
                    this._createBtn(node, wanfaList[listIndex], j);
                }
                listIndex++;
            }
            node.y = innerHeight - 65 * index;
            scrollView.addChild(node);
            index++;
        }
        scrollView.innerHeight = innerHeight;
    },

    _createBtn: function (node, info, j) {
        var btn = duplicateNode(this._nodeList['btn0']);
        btn.setVisible(true);
        btn.getChildByName('label').setString(info['name']);
        btn.x = 100 + j * 200;
        btn.y = 30;
        btn.info = info;
        node.addChild(btn);
        TouchUtil.setOnclickListener(btn, this._clickBtn.bind(this), {swallowTouches: false});
        this._btnList.push(btn);
    },

    _clickBtn: function (target) {
        this._selectWanfa = target.info;
        for (var i = 0; i < this._btnList.length; i++) {
            this._btnList[i].getChildByName('label').setTextColor(cc.color('#ffffff'));
        }
        target.getChildByName('label').setTextColor(cc.color('#ff0000'));
    },

    _clickOk: function () {
        eventManager.dispatchEvent(ClubEvent.FloorAndWanfaFilterEvent, this._selectWanfa);
        this.close();
    },

    _clickPanel: function () {

    },

    /**
     * 获取APP 楼层和玩法信息
     * @returns {*[]}
     */
    getAppFloorAndWanfaInfo: function () {
        var allWanfa = ClubDataManager.getClubFloorWanfaInfo(this._clubId);
        var appWanfa = [];
        var appFloor = [];

        for (var i = 0; i < allWanfa.length; i++) {
            var floorInfo = allWanfa[i];
            if (floorInfo) {
                var floorName = floorInfo['remarks'] || ClubDataManager.getDesc2WanfaName(floorInfo);
                appFloor.push({'name': floorName, 'pos': floorInfo['pos']});
            }
        }
        for (var key in app.map_id) {
            var wanFaName = app.map_name[key];
            var wanFaId = app.map_id[key];
            if (wanFaName && wanFaId) {
                appWanfa.push({'name': wanFaName, 'mapId': wanFaId});
            }
        }

        var allWanfa = [{'name': '全部玩法'}];
        return allWanfa.concat(appFloor).concat(appWanfa);
    },
});